package interfaces.rechercheiti;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;

import donnees.TypeVille;

public class PanelPrefTailleVille extends PanelPref {

	protected JLabel labelTailleVille;
	protected ArrayList<JLabel> labelsTaillesVilles;
	protected ArrayList<JCheckBox> checksTaillesVilles;
    
    public PanelPrefTailleVille (PanelRechercheItineraire _ri) {
		ri = _ri;
        labelTailleVille = new JLabel();
        labelsTaillesVilles = new ArrayList<JLabel>();
        checksTaillesVilles = new ArrayList<JCheckBox>();
        
        setBackground(new Color(255, 255, 102));
        setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        setForeground(new Color(102, 102, 255));

        labelTailleVille.setForeground(new Color(255, 0, 0));
        labelTailleVille.setText("Taille Ville");

        for (String t : TypeVille.getListeTypesVilles()) {
        	JLabel label = new JLabel(t);
        	label.setForeground(new Color(0, 0, 204));
			labelsTaillesVilles.add(label);
			JCheckBox check = new JCheckBox("Eviter");
			check.setOpaque(false);
			check.addActionListener(new ActionListener() {
	        	public void actionPerformed(ActionEvent e) {
	        		checkTailleVille();
	        	}
	        });
			checksTaillesVilles.add(check);
		}
        
        javax.swing.GroupLayout panelTaillesRoutesLayout = new javax.swing.GroupLayout(this);
        ParallelGroup groupeLabel = panelTaillesRoutesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING);
    	for (JLabel label : labelsTaillesVilles) {
            groupeLabel.addComponent(label);
    	}
    	ParallelGroup groupeCheck = panelTaillesRoutesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING);
    	for (JCheckBox check : checksTaillesVilles) {
    		groupeCheck.addComponent(check);
    	}
    	SequentialGroup groupeVertical = panelTaillesRoutesLayout.createSequentialGroup();
    	groupeVertical.addComponent(labelTailleVille);
    	for (int i = 0; i < labelsTaillesVilles.size(); i++) {
    		ParallelGroup group = panelTaillesRoutesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING);
    		groupeVertical.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED);
            groupeVertical.addGroup(group);
    		group.addComponent(labelsTaillesVilles.get(i));
            group.addComponent(checksTaillesVilles.get(i));
		}
        setLayout(panelTaillesRoutesLayout);
        panelTaillesRoutesLayout.setHorizontalGroup(
            panelTaillesRoutesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTaillesRoutesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelTaillesRoutesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelTailleVille)
                    .addGroup(panelTaillesRoutesLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(groupeLabel)
                        .addGap(110, 110, 110)
                        .addGroup(groupeCheck)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 225, Short.MAX_VALUE)
                .addComponent(labelNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(flecheMonter)
                .addComponent(flecheDescendre)
                .addContainerGap())
        );
        panelTaillesRoutesLayout.setVerticalGroup(
            panelTaillesRoutesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(groupeVertical)
            .addGroup(panelTaillesRoutesLayout.createParallelGroup()
                .addComponent(labelNumero)
                .addComponent(flecheMonter)
                .addComponent(flecheDescendre))
        );
        panelTaillesRoutesLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new Component[] {labelNumero, flecheDescendre, flecheMonter});
        panelTaillesRoutesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new Component[] {labelNumero, flecheDescendre, flecheMonter});
    }
    private void checkTailleVille () {
    	boolean isIndif = true;
    	for (JCheckBox check : checksTaillesVilles) {
			isIndif = isIndif && !check.isSelected();
		}
    	setIndifferent(isIndif);
    }
}
